package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ReturnShareView
* */
class ReturnShareView2 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            strokeCap = Paint.Cap.ROUND
            //style = Paint.Style.STROKE
            strokeJoin = Paint.Join.ROUND
            color = context.resources.getColor(R.color.color_079F29)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx + cx / 12, cy + cy / 10)

            //mPaint0.strokeWidth = (cx / 18).coerceAtLeast(minStrokeWidth)
            mPath.apply {
                reset()

                moveTo(cx * 85 / 100, -cy * 55 / 100)
                lineTo(cx * 40 / 100, -cy * 15 / 100)
                lineTo(cx * 40 / 100, -cy * 40 / 100)
                quadTo(
                    -cx * 50 / 100,
                    -cy * 54 / 100,
                    -cx * 80 / 100,
                    cy * 90 / 100
                )

                quadTo(
                    -cx * 90 / 100,
                    -cy * 96 / 100,
                    cx * 40 / 100,
                    -cy * 70 / 100
                )

                lineTo(cx * 40 / 100, -cy * 95 / 100)

                close()
            }
            drawPath(mPath, mPaint0)

            restore()
        }
    }
}